package com.example.myapplication;

import android.content.Intent;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.GridLayout;


public class uc_5 extends AppCompatActivity {

    GridLayout gridLayout;
    String[] chars =new String[]{
            "1","2","3",
            "4","5","6",
            "7","8","9",
            "0","+","-",
            "*","/","=",
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc_5);

        //获取长宽高
        Resources resources = this.getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        float density1 = dm.density;
        int width3 = dm.widthPixels;
        int height3 = dm.heightPixels;

        gridLayout=(GridLayout) findViewById(R.id.root);
        for(int i=0;i<chars.length;i++){
            Button bn=new Button(this);
            bn.setText(chars[i]);
            bn.setTextSize(20);
            bn.setPadding(5,35,5,5);

            GridLayout.Spec rowSpec=GridLayout.spec(i/3+1);

            GridLayout.Spec ColumnSpec=GridLayout.spec(i%3);
            GridLayout.LayoutParams params =new GridLayout.LayoutParams(
                    rowSpec,ColumnSpec);
            params.width=width3/3;
            params.height=height3/6;

           // params.setGravity(Gravity.FILL);

            gridLayout.addView(bn,params);


        }

        Button button4 = (Button) findViewById(R.id.button4);
        button4.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                //Intent是一种运行时绑定（run-time binding）机制，它能在程序运行过程中连接两个不同的组件。
                // 在存放资源代码的文件夹下下，
                Intent i = new Intent(uc_5.this , MainActivity.class);

                // 启动
                startActivity(i);
            }
        });
    }
}
